home *** CD-ROM | disk | FTP | other *** search
- /*
- **
- ** $VER: Dictionary.rexx 1.7 (30.09.2000)
- **
- ** (C)2000 Damir Arh, All Rights Reserved.
- **
- ** E-mail: damir.arh@telesat.si
- ** WWW: http://damir.gajba.net
- **
- ** FUNCTION:
- ** Acts as an interface to a dictionary file in specified format
- **
- ** USAGE:
- ** Dictionary DICTFILE
- **
- ** PARAMETERS:
- ** DICTFILE - dictionary filename
- **
- ** $Id: Dictionary.rexx,v 1.7 2000/09/30 14:51:11 damir Sta $
- **
- ** $Log: Dictionary.rexx,v $
- ** Revision 1.7 2000/09/30 14:51:11 damir
- ** - major rewrite (increased speed and memory requirements, reduced file access)
- **
- ** Revision 1.6 2000/09/30 14:22:32 damir
- ** - rewritten the keyword manipulation to reduce file access
- **
- ** Revision 1.5 2000/09/16 20:51:21 damir
- ** - fixed a bug which caused the script to quit in case of non-alphabetical root search
- **
- ** Revision 1.4 2000/09/02 15:48:34 damir
- ** - fixed a bug introduced in previous revision
- **
- ** Revision 1.3 2000/09/01 11:12:53 damir
- ** - fixed a bug which caused the script to exit in certain cases
- **
- ** Revision 1.2 2000/09/01 10:17:27 damir
- ** - program speed up by indexing the starting letter positions
- **
- ** Revision 1.1 2000/08/31 19:45:10 damir
- ** Initial revision
- **
- */
-
- parse arg DictionaryFile
- options results
-
- if ~open(infile,DictionaryFile,'R') then do
- cecho("Error","Can't open the dictionary file.")
- exit
- end
-
- say "Initializing, please wait..."
-
- /* get the keywords */
-
- NextLine = "empty"
- keywords.TITLE = "Untitled"
- do while NextLine ~= ""
- NextLine = readln(infile)
- FirstWord = word(NextLine,1)
- if left(FirstWord,1) = "#" then do
- key = upper(substr(FirstWord,2))
- keywords.key = subword(NextLine,2)
- end
- end
- t = 0
- Beginning.1 = t
-
- /* find the starting positions for all the letters */
-
- do i = 2 to 27
- do while (upper(left(NextLine,1)) < d2c(c2d('A')-1+i)) & (~eof(infile))
- NextLine = readln(infile)
- parse var NextLine LPart ' - ' RPart
- entry.t = LPart
- description.t = RPart
- t = t + 1
- end
- Beginning.i = t
- end
-
- close(infile)
-
- help()
-
- /* main loop */
-
- Query = ""
- do while Query ~="!"
- writech(stdin,"> ")
- parse pull Query
- if Query = "?" then help()
- else if Query = "!" then exit
- else if word(Query,1) = "#" then say keyword(word(Query,2))
- else if word(Query,1) = "*" then findroot(subword(Query,2))
- else say find(Query)
- end
-
-
- /* functions */
-
- help: /* print out the help text */
- say ""
- say "Dictionary.rexx 1.5 (c)2000 Damir Arh, All rights reserved"
- say ""
- say "Current dictionary file: " || keywords.TITLE
- say ""
- say "Commands:"
- say "? - displays this help text"
- say "! - quits program"
- say "# keyword - returns the contents of the 'keyword'"
- say "* something - returns all dictionary entries that start with 'something'"
- say "something - returns the dictionary entry for 'something'"
- say ""
- return 0
-
- keyword: /* display keyword contents */
- key = upper(arg(1))
- if keywords.key = keywords || '.' || key then return "unknown keyword"
- else return keywords.key
-
- find: /* display dictionary entry */
- l = c2d(upper(left(arg(1),1)))-c2d('A')+1
- if l<1 | l>26 then l=1
- u = l + 1
- do i = Beginning.l to Beginning.u - 2
- if upper(entry.i) = upper(arg(1)) then return description.i
- end
- return "word not in dictionary"
-
- findroot: /* display all entries with the given root */
- l = c2d(upper(left(arg(1),1)))-c2d('A')+1
- if l<1 | l>26 then l=1
- u = l + 1
- do i = Beginning.l to Beginning.27 - 2
- if upper(left(entry.i,length(arg(1)))) = upper(arg(1)) then say entry.i '-' description.i
- if upper(left(entry.i,length(arg(1)))) > upper(arg(1)) then return 0
- end
- return 0
-